//
//  Controller02.swift
//  Swift30Days
//
//  Created by licheng ke on 2017/2/27.
//  Copyright © 2017年 licheng ke. All rights reserved.
//

import Foundation
import UIKit

class Controller02: UIViewController,UITableViewDelegate,UITableViewDataSource,VideoCellDelegate {
    
    var strings = ["30 Days Swift", "这些字体特别适合打「奋斗」和「理想」", "谢谢「造字工房」，本案例不涉及商业使用", "使用到造字工房劲黑体，致黑体，童心体", "呵呵，再见🤗 See you next Project", "微博 @Allen朝辉",
                "测试测试测试测试测试测试",
                "123",
                "Alex",
                "@@@@@@"]
    
    var fontNames = ["MFTongXin_Noncommercial-Regular", "MFJinHei_Noncommercial-Regular", "MFZhiHei_Noncommercial-Regular", "Gaspar Regular"]

    var tableView : UITableView!
    
    var currentFontIndex = 0;
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        configUI();
    }
    
    func configUI() {
        tableView = UITableView();
        view.addSubview(tableView);
        tableView.backgroundColor = UIColor.clear;
        tableView.tableFooterView = UIView();
        tableView.snp.makeConstraints { (maker) in
            maker.top.equalTo(topLayoutGuide.snp.top);
            maker.leading.equalTo(0);
            maker.trailing.equalTo(0);
            maker.bottom.equalTo(bottomLayoutGuide.snp.top);
        }
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.allowsSelection = false;
        
        let barBtn = UIBarButtonItem(title: "next Font", style: .plain, target: self, action: #selector(changeFonts))
        navigationItem.rightBarButtonItem = barBtn;
    }
    
    func changeFonts() {
        currentFontIndex = (currentFontIndex + 1) % 4;
        tableView.reloadData();
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    //MARK: -dataSoure & delegate
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return strings.count;
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "abc");
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "abc");
            cell?.textLabel?.textColor = UIColor.white;
            cell?.backgroundColor = UIColor.black;
        }
        cell?.textLabel?.text = strings[indexPath.row] ;
        cell?.textLabel?.font = UIFont(name: fontNames[currentFontIndex], size: 16);
        return cell!;
    }
    
    func viewCellAction(_ myCell: VideoCell) {
        print("....play video");
    }
    
}
